package com.br.modelo.dao;

import java.util.List;

import com.br.modelo.entidades.Setor;
import com.br.modelo.entidades.User;

public class UserDao {

	private User user = new User();
	private DaoResource daoResource = new DaoResource();
	
	public void saveUser(String nmUser, String use, String password, String admin, int cdSetor) {
		
		List<Setor> set = daoResource.select("from Setor where cdSetor = :id", "id", cdSetor);
		
		user.setNmUser(nmUser);
		user.setUser(use);
		user.setPassword(password);
		user.setAdmin(admin);
		user.setSetor(set.get(0));
		
		daoResource.save(user);
	}
	
	public void mudaSenha(String use, String password) {
		List<User> ltUser = daoResource.select("from User where user = :user", "user", use);
		ltUser.get(0).setPassword(password);
		
		daoResource.save(ltUser.get(0));
	}
	
	public void inativaUser(String use) {
		List<User> ltUser = daoResource.select("from User where user = :user", "user", use);
		ltUser.get(0).setInativo("s");
		
		daoResource.save(ltUser.get(0));
	}
}
